#include "pthread.h"
#include "stdio.h"
#include "unistd.h"
#include "sys/time.h"

int sqr_fun(int num)
{
    int result = num * num;
    sleep(1);
    return result;
}

int main()
{
    int num[5] = {1, 2, 3, 4, 5};
    int sum = 0;
    int sqr[5] = {0};
    // 定义时间
    struct timeval start, end;
    gettimeofday(&start, NULL);
    for (size_t i = 0; i < 5; i++)
    {
        sqr[i] = sqr_fun(num[i]);
    }
    gettimeofday(&end, NULL);

    printf("time: %ld\n", end.tv_sec - start.tv_sec);
    for (size_t i = 0; i < 5; i++)
    {
        sum += sqr[i];
    }
    printf("sum: %d\n",sum);

    return 0;
}